#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	char a[200],b[200];
	char mars1[16][5]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
	char mars2[16][5]={"tret","tam" , "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
	int yu[200];
	int n,i,j,k=0,num=0,z=0;
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		num=0;z=0;k=0;yu[0]=0;yu[1]=0;
		
		
		gets(a);
		//printf("len=%d\n",strlen(a));
		
		
		if(a[0]>='0' && a[0]<='9')
		{
			for ( j=strlen(a)-1 ; j>=0 ; j-- )
				{
					num+=(a[j]-'0')*pow(10,z++);
					//printf("%c\n",a[j]);
				}
			//printf("%d\n",num);
			while(1)
			{
				yu[k++]=num%13;
				num=num/13;
				if(num==0)
				{
					if(k==1)
						printf("%s\n",mars1[ yu[k-1] ]);
					else if( yu[k-2]!=0 )
						printf("%s %s\n",mars2[ yu[k-1] ],mars1[ yu[k-2] ]);
					else
						printf("%s\n",mars2[ yu[k-1] ]);
					break;	
				}
			}
		}
		
		if(a[0]>='a' && a[0]<='z')
		{
			if(strlen(a)==4)
				printf("0\n");
			if(strlen(a)==3)
				for(j=1;j<=12;j++)
				{
					//printf("%s %s\n",a,mars1[j]);
					//printf("%d\n",strlen(mars1[j]));
					//a[0]==mars1[j][0]&&a[1]==mars1[j][1]&&a[2]==mars1[j][2]
					if(strcmp(a,mars1[j])==0)
					{
						printf("%d\n",j);break;
					}
					if(strcmp(a,mars2[j])==0)
					{
						printf("%d\n",(j)*13);break;
					}
				}
			if(strlen(a)==7)
			{
				for(j=1;j<=12;j++)
				{
					if(a[0]==mars2[j][0]&&a[1]==mars2[j][1]&&a[2]==mars2[j][2])
						num+=(j)*13;
					if(a[4]==mars1[j][0]&&a[5]==mars1[j][1]&&a[6]==mars1[j][2])
						num+=j;
				}
				printf("%d\n",num);
			}
		}
		
	}
	return 0;
}
